package jmvcclab.View;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import jmvcclab.Model.MainData;

/**
 *
 * @author home
 */
public class IOPanel extends JPanel implements ActionListener {

    public static JTextField text;
    private JButton goButton;
    private MainData mainData;
    public IOPanel(MainData mainData) {
        super();
        this.mainData = mainData;
        text = new JTextField();
        text.setPreferredSize(new Dimension(160, 25));
        this.add(text);
        goButton = new JButton("Go!");
        goButton.setPreferredSize(new Dimension(60, 25));
        goButton.setBackground(Color.red);
        goButton.setForeground(Color.white);
        goButton.setBorderPainted(false);
        goButton.addActionListener(this);
        this.add(goButton);
        this.setVisible(true);
    }

    /*действие, получаемое при нажатии на кнопку Go*/
    public void actionPerformed(ActionEvent e) {
        String command = e.getActionCommand();
        if(command.equals("Go!")){
            mainData.Query = getString();
        }
    }
    public void setString(String value){
        text.setText(value);
    }
    public String getString() {
        return text.getText();
    }
}
